#ifndef QTAV_QML_QQUICKRENDERER_H
#define QTAV_QML_QQUICKRENDERER_H

#include <QmlAV/Export.h>
#include <QtAV/VideoRenderer.h>
#include <QtQuick/QQuickItem>

namespace QtAV
{
extern QMLAV_EXPORT VideoRendererId VideoRendererId_QQuickItem;

class QQuickItemRendererPrivate;
class QMLAV_EXPORT QQuickItemRenderer : public QQuickItem, public VideoRenderer
{
    Q_OBJECT
    DPTR_DECLARE_PRIVATE(QQuickItemRenderer)
    Q_PROPERTY(QObject* source READ source WRITE setSource NOTIFY sourceChanged)
    Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
    Q_ENUMS(FillMode)
public:
    enum FillMode
    {
        Stretch            = Qt::IgnoreAspectRatio,
        PreserveAspectFit  = Qt::KeepAspectRatio,
        PreserveAspectCrop = Qt::KeepAspectRatioByExpanding
    };

    explicit QQuickItemRenderer(QQuickItem *parent = 0);
    ~QQuickItemRenderer() {}
    virtual VideoRendererId id() const;

    QObject *source() const;
    void setSource(QObject *source);

    FillMode fillMode() const;
    void setFillMode(FillMode mode);

Q_SIGNALS:
    void sourceChanged();
    void fillModeChanged(QQuickItemRenderer::FillMode);

protected:
    virtual void convertData(const QByteArray &data);
    virtual bool needUpdateBackground() const;
    virtual bool needDrawFrame() const;
    virtual void drawFrame();

    // QQuickItem interface
    virtual QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *data);

    // AVOutput interface
    virtual bool write();

private:

};
typedef QQuickItemRenderer VideoRendererQQuickItem;
}

#endif // QTAV_QML_QQUICKRENDERER_H
